package org.example.controller;


import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.example.feign.UserOpenFeignClient;
import org.example.vo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    UserOpenFeignClient userOpenFeignClient;


    @Autowired
    RestTemplate restTemplate;

//    @RequestMapping(value = "getData", method = RequestMethod.GET)
    @GetMapping("getData")
    public Object getData() {
        ResponseEntity<User> forEntity = restTemplate.getForEntity("http://zhanggm-user/user/getById?id=1", User.class);
        User body = forEntity.getBody();
        return userOpenFeignClient.getById(1);

    }

    @GetMapping("test")
    @HystrixCommand(fallbackMethod = "testFallback")
    public Object test(String username) {
        return "hello user:" + username;
    }

    public Object testFallback(String username) {
        return "testFallback user:" + username;
    }








}
